package pers.vic.blog.module.front.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import pers.vic.blog.module.api.model.BlogThirdUser;
import pers.vic.blog.module.api.service.BlogThirdUserService;
import pers.vic.blog.constant.ThirdProperties;

/**
 * @author Vic.xu
 * @description:
 * @date: 2020/7/21 0021 17:53
 */
public abstract class AbstractAuthService {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private BlogThirdUserService blogThirdUserService;

    /**
     * 通过code获取access_token
     * @param code
     * @return
     */
    public abstract String getAccessToken(String code);

    /**
     * 根据access_token  获取用户信息
     * @param accessToken
     * @return
     */
    public abstract BlogThirdUser getUserInfo(String accessToken);

    /**
     * 获得配置文件
     * @return
     */
    public abstract ThirdProperties.ThirdAuthConfig config();

    /**
     * 根据code获取用户信息，并更新本地数据库
     * @param code
     * @return
     */
    public BlogThirdUser findUserInfoByCode(String code) {
        String accessToken = getAccessToken(code);
        BlogThirdUser user = getUserInfo(accessToken);
        user = blogThirdUserService.checkUser(user);
        return user;

    }


}
